<?php

// Main entry to the server
// All the requests will be handled from here.
// Pattern for HTTP request is: controller & action & other arguments

// getting "controller" value
$controller = $_REQUEST["controller"];
//$controller = "Student";

if (isset($controller)){
	// including all the required stuff
	// controllers and EntryPoint
	require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . "/SmartTuition/SmartTuition.Model/EntryPoint.php");
	
	// detecting appropriate controller to work with
	require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . "/SmartTuition/SmartTuition.Server/Controllers" . "/$controller" . "Controller.php");
	// building Controller class name to create it dynamically
	$controllerName = $controller . "Controller";
	// creating instance of appropriate controller
	$controllerEntity = new $controllerName($unitOfWork);
	
	// detecting whether action exists
	$action = $_REQUEST["action"];
	//$action = "Index";
	
	if (isset($action)){
		try{
			// calling action(method) from controller
			call_user_func(array(&$controllerEntity, $action));
		}
		catch(Exception $e){
			// no such action
			//  terminate the script
			exit(-1);
		}
	}
}
else{
	// http request not according to the pattern
	// missing "controller" value in the request parameters
	
	// terminate script
	exit(-1);
}
